//
//  CacheTool.m
//  bus
//
//  Created by hychen on 2017/4/8.
//  Copyright © 2017年 Hychen. All rights reserved.
//

#import "CacheTool.h"
#import <YYCache/YYCache.h>

#define defaultCacheName @"Bus"

@implementation CacheTool
static id _instance;
+ (instancetype)allocWithZone:(struct _NSZone *)zone
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [super allocWithZone:zone];
    });
    return _instance;
}

+ (instancetype)sharedTool
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[self alloc] init];
    });
    return _instance;
}

- (id)copyWithZone:(NSZone *)zone
{
    return _instance;
}

- (instancetype)init{
    if (self = [super init]) {
        _cache = [YYCache cacheWithName:defaultCacheName];
    }
    return self;
}

- (id<NSCoding>)objectForKey:(NSString *)key{
    return [_cache objectForKey:key];
}

- (void)setObject:(id<NSCoding>)object forKey:(NSString *)key{
    [_cache setObject:object forKey:key];
}
@end
